import request, { communityRequest } from '@/utils/request'

// 仓库管理API接口
export const warehouseApi = {
  /**
   * 获取所有小区列表（用于下拉选择）
   * @returns {Promise}
   */
  getAllCommunities() {
    return communityRequest({
      url: '/community/selcomm',
      method: 'get'
    })
  },

  /**
   * 获取所有仓库列表（用于下拉选择）
   * @returns {Promise}
   */
  getAllWarehouses() {
    return request({
      url: '/warehouse/all',
      method: 'get'
    })
  },

  /**
   * 分页查询仓库列表
   * @param {Object} params 查询参数
   * @param {string} params.warehouseName 仓库名称
   * @param {number} params.status 状态
   * @param {number} params.currentPage 当前页
   * @param {number} params.pageSize 每页大小
   * @returns {Promise}
   */
  getWarehousePage(params) {
    return request({
      url: '/warehouse/page',
      method: 'get',
      params
    })
  },

  /**
   * 根据ID获取仓库详情
   * @param {string} warehouseId 仓库ID
   * @returns {Promise}
   */
  getWarehouseById(warehouseId) {
    return request({
      url: `/warehouse/${warehouseId}`,
      method: 'get'
    })
  },

  /**
   * 新增仓库
   * @param {Object} data 仓库信息
   * @returns {Promise}
   */
  addWarehouse(data) {
    return request({
      url: '/warehouse',
      method: 'post',
      data
    })
  },

  /**
   * 更新仓库信息
   * @param {Object} data 仓库信息
   * @returns {Promise}
   */
  updateWarehouse(data) {
    return request({
      url: '/warehouse',
      method: 'put',
      data
    })
  },

  /**
   * 更新仓库状态
   * @param {string} warehouseId 仓库ID
   * @param {number} status 状态
   * @returns {Promise}
   */
  updateWarehouseStatus(warehouseId, status) {
    return request({
      url: `/warehouse/${warehouseId}/status/${status}`,
      method: 'put'
    })
  },

  /**
   * 删除仓库
   * @param {string} warehouseId 仓库ID
   * @returns {Promise}
   */
  deleteWarehouse(warehouseId) {
    return request({
      url: `/warehouse/${warehouseId}`,
      method: 'delete'
    })
  },

  /**
   * 批量删除仓库
   * @param {Array} warehouseIds 仓库ID数组
   * @returns {Promise}
   */
  batchDeleteWarehouse(warehouseIds) {
    return request({
      url: '/warehouse/batch-delete',
      method: 'delete',
      data: { warehouseIds }
    })
  },

  /**
   * 批量更新仓库状态
   * @param {Array} warehouseIds 仓库ID数组
   * @param {number} status 状态
   * @returns {Promise}
   */
  batchUpdateWarehouseStatus(warehouseIds, status) {
    return request({
      url: '/warehouse/batch-status',
      method: 'put',
      data: { warehouseIds, status }
    })
  },

  /**
   * 导出仓库数据
   * @param {Object} params 导出参数
   * @returns {Promise}
   */
  exportWarehouseData(params) {
    return request({
      url: '/warehouse/export',
      method: 'get',
      params,
      responseType: 'blob'
    })
  },

  /**
   * 导入仓库数据
   * @param {FormData} formData 文件数据
   * @returns {Promise}
   */
  importWarehouseData(formData) {
    return request({
      url: '/warehouse/import',
      method: 'post',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },

  /**
   * 获取仓库统计信息
   * @returns {Promise}
   */
  getWarehouseStats() {
    return request({
      url: '/warehouse/stats',
      method: 'get'
    })
  }
}
